package io.bytestream;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Objects;

public class Test5 {
    public static void main(String[] args) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader("AdvancedCode/src/io/bytestream/info/info.txt"));
            int i;
            char[] b = new char[8];
            while ((i = reader.read(b)) > 0) {
                System.out.print(new String(b, 0, i));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            // 方式三：Objects.requireNonNull()
            try {
                Objects.requireNonNull(reader).close();
            } catch (IOException | NullPointerException e) {
                e.printStackTrace();
            }
        }

    }
}
